package DBConnection;

import java.sql.DriverManager;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;

public class DatabaseConnection {
	
	//Global Variables
	private Connection cn = null;
	private String adress = null;;
	private String user =  null;
	private String password = null;
	private String dbname = null;
	
	public DatabaseConnection(String adress, String dbname, String user, String password) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException{
		
		this.adress = adress;
		this.user = user;
		this.password = password;
		this.dbname = dbname;
		
		connection();
		
	}
	
	
	public void connection() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException{
		
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		
		this.setCn((Connection) DriverManager.getConnection(this.getAdress()+"/"+this.getDbname(), this.getUser(), this.getPassword()));
		
        
	}


	private String getDbname() {
		return dbname;
	}


	private String getAdress() {
		return adress;
	}


	private String getUser() {
		return user;
	}


	private String getPassword() {
		return password;
	}


	private void setCn(Connection cn) {
		this.cn = cn;
	}


	public Connection getCn() {
		return cn;
	}


}